
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>修改个人密码</title>
    <script type="text/javascript" src="/admin/js/jquery.min.js"></script>
    <link rel="stylesheet" href="/layui-v2.2.5/layui/css/layui.css" media="all">
    <script type="text/javascript" src="/layui-v2.2.5/layui/layui.js" charset="utf-8"></script>

    <style>
        .login-input{
            height: 32px;
        }
        .login{
            top: 50px;
            left: 2%;
            padding: 0;
            width: 90%;
        }
        .row div{
            display: inline-block;
        }
        .row{
            margin-left: 15%;
        }
        .msg-btn{
            border: 0;
            background: #27B5F3;
            padding: 8px 30px;
            color:#FFF;
            border-radius: 3px;
            margin-left: 46%;
            margin-top: 30px;
        }
        .layui-layer-content{
            padding-top: 120px;
            text-align: center;
        }
        .layui-layer-btn a{
            position: relative;
            bottom: 10px;
            margin: 0 25px;
        }
        body .demo-class .layui-layer-title{background:#c00; color:#fff; border: none;}
        .layui-input, .layui-select, .layui-textarea{
            border: 1px solid #CCC;
        }
        .layui-input{
            width: 50%;
        }
        .layui-form-label{
            margin-left: 20%;
        }
        .layui-form{
            padding-top: 50px;
        }
    </style>
</head>
<body>
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">原密码：</label>
        <div class="layui-input-block">
            <input type="password" name="pswds" id="pswds" class="layui-input" style="width: 1px;display: inline-block;border: 0;padding:0;">
            <input type="password" name="pswd" id="pswd" class="layui-input" style="display: inline-block">
            <span style="color: #FF8D24;font-size: 12px;display: none;" class="errmsg1"> 请输入原密码！</span>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新密码：</label>
        <div class="layui-input-block">
            <input type="password" name="newPswd" id="newPswd" class="layui-input">
            <span style="color: #FF8D24;font-size: 12px;display: none" class="errmsg2">不能和原密码相同！</span>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认新密码：</label>
        <div class="layui-input-block">
            <input type="password" name="newPswdSure" id="newPswdSure" class="layui-input">
            <span style="color: #FF8D24;font-size: 12px;display: none" class="errmsg3">两次密码不一致！</span>
        </div>
    </div>
    <button id="btn" type="button" class="msg-btn">提交</button>
</form>
</body>

    <script type="text/javascript">

    //登录操作
    $(function () {

        $('#btn').click(function () {
            var newPswd=$("#newPswd").val();
            var pswd = $('#pswd').val();
            var newPswdSure=$("#newPswdSure").val();
           if (pswd == ''||pswd==null) {
                /!* layer.msg("请输入原来的密码")*!/
                $(".errmsg1").show();
                $('#pswd').focus();
                return false;
            }
            if (newPswd == '') {
                /!*layer.msg("请输入新的密码")*!/
                $(".errmsg21").show();
                $('#newPswd').focus();
                return false;
            }
            if (newPswdSure == '') {
                /!* layer.msg("请再次输入新密码")*!/
                $(".errmsg3").show();
                $('#newPswdSure').focus();
                return false;
            }
            if(newPswd!=newPswdSure){
                $(".errmsg3").show();
                $('#newPswdSure').focus();
                return false
            }else{
                $(".errmsg3").hide();
            }

            $.ajax({
                url:'/admin/updatePswd',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:{
                    pswd:pswd,
                    newPswd:newPswd
                },
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){
                    /*console.log(xhr)
                     console.log('发送前')*/
                },
                success:function(data){
                    console.log(data);
                    if (data.code=="true"){
                        alert("修改成功，请重新登录");
                        window.location.href = "/";
                    }else {
                        alert("原密码错误");
                    }
                },
            })

        });
        $('#pswd').bind('input propertychange', function () {
            var pswd=$("#pswd").val();
            if(pswd!=null&&pswd!='') {
                /!*layer.msg("请输入原来的密码！")*!/
                $(".errmsg1").hide();
            }else{
                $(".errmsg1").show();
            }
        })
        $("#pswd").blur(function () {
            var pswd=$("#pswd").val();
            if(pswd==null||pswd==''){
                /!*layer.msg("请输入原来的密码！")*!/
                $(".errmsg1").show();
                return false;
            }else {
                $(".errmsg1").hide();
            }
        })
        $("#newPswd").blur(function () {
            var newPswd=$("#newPswd").val();
            var pswd=$("#pswd").val();
            if(pswd==newPswd&&pswd!=null&&pswd!=''){
                /!* layer.msg("新密码不能和原来密码相同！")*!/
                $(".errmsg2").show();
                $("#newPswd").val("");
                $("#newPswd").focus();
                return false;
            }else {
                $(".errmsg2").hide();
            }
        })
        $('#newPswd').bind('input propertychange', function () {
            var newPswd=$("#newPswd").val();
            var newPswdSure = $(this).val();
            if(newPswdSure==newPswd){
                $('.errmsg3').hide();
            }else{
                $('.errmsg3').show();
            }
        })
        $("#newPswdSure").blur(function () {
            var newPswd=$("#newPswd").val();
            var newPswdSure=$("#newPswdSure").val();
            if(newPswdSure!=newPswd){
                /!*layer.msg("两次密码输入不一致，请核对后进行操作")*!/
                $('.errmsg3').show();
                return false;
            }else{
             $('.errmsg3').hide();
             }
        })
        $('#newPswdSure').bind('input propertychange', function () {
            var newPswd=$("#newPswd").val();
            var newPswdSure = $(this).val();
            if(newPswdSure==newPswd){
                $('.errmsg3').hide();
            }else{
                $('.errmsg3').show();
            }
        })
    });
    window.onload=function(){
    }
</script>
</html>